package admin.controllers;

import java.io.IOException;
import java.net.URLDecoder;
import java.util.TreeMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.NewsModel;

import admin.data.NewsData;

public class DeleteNewsServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		String path = ((HttpServletRequest) request).getRequestURI();
		String id = URLDecoder.decode(path.toLowerCase().replaceAll("/admin/delete-news/", ""),"UTF-8");
		
		NewsData newsData = new NewsData();
		NewsModel news = newsData.getNews(id);
		
		if (newsData != null) {
			newsData.delete(news);
		}
		
		response.sendRedirect("/admin/list-news");
	}
}
